import React, { Component } from 'react'
import {connect} from 'react-redux'
import {Item,Types} from '../../types/types'
import CollectionItem from '../../component/collectionItem'

interface Iprops{
    match:any,
    list:Types[],
    history:any
}

interface Istate{
}



class Classify extends Component <Iprops,Istate>{
    componentDidMount(){
        console.log(this.props.match.params.type)

        
        // this.setState({
        //     classify:
        // })
    }
    render() {
        let data = this.props.list.filter((item:Types) => item.type === this.props.match.params.type)
        console.log(data[0].children)
        return (
            <div>
                <button onClick={this.back}>返回</button>
                {data[0].children.map((item:Item) => <CollectionItem type={this.props.match.params.type} {...item} key={item.t_id}></CollectionItem>)}
            </div>
        )
    }
    back =( ) => {
        this.props.history.push('/main/home')
    }
}

let stateMapToProps = (state:any) => {
    return {
        list:state.list
    }
}


let dispatchMapToProps = (dispatch:any) => {

}

export default connect(stateMapToProps)(Classify)